package net.sky.oaxz.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sky.oaxz.bean.XzSchool;
import net.sky.oaxz.dao.XzSchoolDao;

public class AddSchoolServlet extends HttpServlet {

	private static final long serialVersionUID = -1786309270087237268L;

	/**
	 * Constructor of the object.
	 */
	public AddSchoolServlet() {
		super();
	}

	/**
	 * Destruction of the servlet. <br>
	 */
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}

	/**
	 * The doGet method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to get.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html;charset=UTF-8");
		doPost(request,response);
	}

	/**
	 * The doPost method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to post.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html;charset=UTF-8");
		request.setCharacterEncoding("UTF-8");
		PrintWriter out = response.getWriter();
		
		String schName=request.getParameter("schname").trim();
		String schDean=request.getParameter("schdean").trim();
		String schAddress=request.getParameter("schaddress").trim();
		String schBegintime=request.getParameter("schbegintime").trim();
		String schTel=request.getParameter("schtel").trim();
		String schDesc=request.getParameter("schdesc").trim();
		int schSeq=Integer.parseInt((request.getParameter("schseq")).trim());
		int schType=Integer.parseInt(request.getParameter("schtype").trim());
		//out.print(schType);
		
		XzSchool ls=new XzSchool();
		ls.setSchName(schName);
		ls.setSchDean(schDean);
		ls.setSchAddress(schAddress);
		ls.setSchBegintime(schBegintime);
		ls.setSchTel(schTel);
		ls.setSchDesc(schDesc);
		ls.setSchSeq(schSeq);
		ls.setSchType(schType);
		ls.setSchStatus(1);
		
		XzSchoolDao sd=new XzSchoolDao();
		int count=sd.addsch(ls);
		if(count>0){
			out.print("<script type='text/javascript'>alert('添加成功！');location.replace('../xuzhaoNew/backstage/add_school.jsp');</script>");
		}else{
			out.print("<script type='text/javascript'>alert('添加失败！');history.go(-1);</script>");
		}
	}

	/**
	 * Initialization of the servlet. <br>
	 *
	 * @throws ServletException if an error occurs
	 */
	public void init() throws ServletException {
		// Put your code here
	}

}
